home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / gtlayout-source.lha / LTP_PrintBoxLine.c < prev    next >
C/C++ Source or Header  |  1996-10-09  |  4KB  |  207 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14.  
  15. /*****************************************************************************/
  16.  
  17.  
  18. BOOL
  19. LTP_PrintLinePadded(LayoutHandle *Handle,LONG Left,LONG Top,LONG Space,STRPTR Line,LONG Len)
  20. {
  21.     LONG Size,Start,Count,i,Width;
  22.     struct RastPort *RPort;
  23.  
  24.     RPort    = &Handle->RPort;
  25.     Size    = 0;
  26.     Start    = 0;
  27.     Count    = 0;
  28.     i        = 0;
  29.     Width    = 0;
  30.  
  31.     while(i < Len && Line[i] == ' ')
  32.     {
  33.         Size++;
  34.         i++;
  35.     }
  36.  
  37.     while(i < Len)
  38.     {
  39.         while(i < Len && Line[i] != ' ')
  40.         {
  41.             Size++;
  42.             i++;
  43.         }
  44.  
  45.         Width += TextLength(RPort,&Line[Start],Size);
  46.  
  47.         Count++;
  48.  
  49.         while(i < Len && Line[i] == ' ')
  50.             i++;
  51.  
  52.         Start    = i;
  53.         Size    = 0;
  54.     }
  55.  
  56.     if(Width)
  57.     {
  58.         LONG j,TextLeft;
  59.  
  60.         Space -= Width;
  61.  
  62.         j = Start = Size = 0;
  63.  
  64.         while(j < Len && Line[j] == ' ')
  65.         {
  66.             Size++;
  67.             j++;
  68.         }
  69.  
  70.         LTP_SetAPen(RPort,Handle->TextPen);
  71.  
  72.         TextLeft = Left;
  73.  
  74.         Count--;
  75.  
  76.         for(i = 0 ; i <= Count ; i++)
  77.         {
  78.             if(i)
  79.             {
  80.                 LONG Delta;
  81.  
  82.                 if(Delta = (Space * i) / Count - (Space * (i - 1)) / Count)
  83.                 {
  84.                     LTP_SetAPen(RPort,Handle->BackgroundPen);
  85.                     LTP_FillBox(RPort,TextLeft,Top,Delta,Handle->GlyphHeight);
  86.                     LTP_SetAPen(RPort,Handle->TextPen);
  87.  
  88.                     TextLeft += Delta;
  89.                 }
  90.             }
  91.  
  92.             while(j < Len && Line[j] != ' ')
  93.             {
  94.                 Size++;
  95.                 j++;
  96.             }
  97.  
  98.             LTP_PrintText(RPort,&Line[Start],Size,TextLeft,Top);
  99.  
  100.             TextLeft += TextLength(RPort,&Line[Start],Size);
  101.  
  102.             while(j < Len && Line[j] == ' ')
  103.                 j++;
  104.  
  105.             Start = j;
  106.             Size = 0;
  107.         }
  108.  
  109.         return(TRUE);
  110.     }
  111.     else
  112.         return(FALSE);
  113. }
  114.  
  115.  
  116. /*****************************************************************************/
  117.  
  118.  
  119. VOID
  120. LTP_PrintLine(LayoutHandle *handle,LONG alignType,LONG left,LONG top,LONG space,STRPTR line,LONG len)
  121. {
  122.     struct RastPort *rp;
  123.  
  124.     rp = &handle->RPort;
  125.  
  126.     LTP_SetPens(rp,handle->BackgroundPen,handle->BackgroundPen,JAM2);
  127.  
  128.     if(alignType == ALIGNTEXT_PAD)
  129.     {
  130.         if(LTP_PrintLinePadded(handle,left,top,space,line,len))
  131.             return;
  132.     }
  133.     else
  134.     {
  135.         struct TextExtent extent;
  136.         LONG width;
  137.  
  138.         len        = TextFit(rp,line,len,&extent,NULL,1,space,32767);
  139.         width    = extent.te_Width;
  140.  
  141.         if(len)
  142.         {
  143.             LONG textLeft;
  144.  
  145.             switch(alignType)
  146.             {
  147.                 case ALIGNTEXT_LEFT:
  148.  
  149.                     textLeft = left;
  150.  
  151.                     if(width < space)
  152.                         LTP_FillBox(rp,left + width,top,space - width,handle->GlyphHeight);
  153.  
  154.                     break;
  155.  
  156.                 case ALIGNTEXT_CENTERED:
  157.  
  158.                     textLeft = left + (space - width) / 2;
  159.  
  160.                     if(width < space)
  161.                     {
  162.                         LONG fill;
  163.  
  164.                         if((fill = (space - width) / 2) > 0)
  165.                             LTP_FillBox(rp,left,top,fill,handle->GlyphHeight);
  166.                         else
  167.                             fill = 0;
  168.  
  169.                         fill += width;
  170.  
  171.                         if(fill < space)
  172.                             LTP_FillBox(rp,left + fill,top,space - fill,handle->GlyphHeight);
  173.                     }
  174.  
  175.                     break;
  176.  
  177.                 case ALIGNTEXT_RIGHT:
  178.  
  179.                     textLeft = left + space - width;
  180.  
  181.                     if(width < space)
  182.                         LTP_FillBox(rp,left,top,space - width,handle->GlyphHeight);
  183.  
  184.                     break;
  185.             }
  186.  
  187.             LTP_SetAPen(rp,handle->TextPen);
  188.             LTP_PrintText(rp,line,len,textLeft,top);
  189.  
  190.             return;
  191.         }
  192.     }
  193.  
  194.     LTP_FillBox(rp,left,top,space,handle->GlyphHeight);
  195. }
  196.  
  197.  
  198. /*****************************************************************************/
  199.  
  200.  
  201. VOID
  202. LTP_PrintBoxLine(LayoutHandle *handle,ObjectNode *node,LONG index)
  203. {
  204.     if(node->Special.Box.Lines && node->Special.Box.Lines[index])
  205.         LTP_PrintLine(handle,node->Special.Box.AlignText,node->Left + 4,node->Top + 2 + index * handle->GlyphHeight,node->Width - 8,node->Special.Box.Lines[index],strlen(node->Special.Box.Lines[index]));
  206. }
  207.